package com.xc.freeapp.account.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.xc.freeapp.bean.AuthInfo;
import com.xc.freeapp.common.CheckUtils;
import com.xc.freeapp.common.ResponseBean;
import com.xc.freeapp.entity.Diseasesdetail;
import com.xc.freeapp.entity.Doctor;
import com.xc.freeapp.entity.Drugdetail;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.response.bean.AllSearchResponse;
import com.xc.freeapp.service.DiseasesService;
import com.xc.freeapp.service.DoctorService;
import com.xc.freeapp.service.DrugdetailService;
import com.xc.freeapp.util.AuthUtil;
import com.xc.freeapp.util.TokenAnnotation;

@Controller
@RequestMapping("/search")
@Api(value = "/search",description="全局搜索")
public class AllSearchController extends AbstractController {
	@Autowired
	DoctorService doctorService;
	@Autowired
	DrugdetailService drugdetailService;
	@Autowired
	DiseasesService diseasesService;
	
	@TokenAnnotation(required=false)
	@RequestMapping(value = "", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "搜索接口")
	public List<AllSearchResponse> searchAll(@RequestParam(value= "keyWord")   String keyWord) throws BaseException {
		List<AllSearchResponse>  responselist =new ArrayList<AllSearchResponse>();
		AuthInfo authInfo = AuthUtil.getAuthInfo(getRequest());
		List<Doctor> doctorlist =doctorService.getdoctorbykeyword(keyWord, authInfo.getAppId());
		List<Drugdetail> drugdetaillist  =drugdetailService.selectByKeyWord(keyWord);
		List<Diseasesdetail> diseasesdetaillist = diseasesService.selectByKeyWord(keyWord);
		AllSearchResponse  doctorResponse = new AllSearchResponse(1, "相关医生", doctorlist);
		AllSearchResponse  diseasesdetailResponse = new AllSearchResponse(2, "相关病症", diseasesdetaillist);
		AllSearchResponse  drugdetailResponse = new AllSearchResponse(3, "相关药品", drugdetaillist);
		responselist.add(drugdetailResponse);
		responselist.add(diseasesdetailResponse);
		responselist.add(doctorResponse);
		return responselist;
	}

}
